<?php

$this->load->view("header2");
print_r($where_sql);

?>

<input type="hidden"  id="where_sql" value="<?= !empty($where_sql)?$where_sql:''; ?>" >

<?php


$srt_flg=true;
$_object_case_type='';
if(!empty($post_data["object_case_type"])){

  foreach($post_data["object_case_type"] as $_flg => $_val){

    if($srt_flg){
      $srt_flg=false;
      $_object_case_type.=$_val;  

    }else{
      $_object_case_type.=",".$_val;  
    }
    
  }

}
?>

<input type="hidden"  id="object_case_type" value="<?=$_object_case_type; ?>" >

<div id="content">

    <link rel="stylesheet" href="<?= base_url() ?>css/crid_style.css" />
    <link rel="stylesheet" type="text/css" href="<?= base_url() ?>css/flexigrid.pack.css" />
    <script type="text/javascript" src="<?= base_url() ?>js/flexigrid.pack.js"></script>
    <script type="text/javascript" src="<?= base_url() ?>js/flexigrid2.js"></script>

    <table class="flexme4" style="display: none"></table>

    


    <script type="text/javascript">

        $(".flexme4").flexigrid({
            url: '/object/object_sf_josn',
            dataType: 'json',
            colModel: [
                {
                    display: '編號',
                    name: 'object_id',
                    width: '60',
                    sortable: true,
                    align: 'center'

                },
                {
                    display: '所有權人',
                    name: 'owner',
                    width: 100,
                    sortable: true,
                    align: 'center'
                },
                {
                    display: '委托人',
                    name: 'principal',
                    width: 100,
                    sortable: true,
                    align: 'left'
                },
                {
                    display: '物件案名',
                    name: 'case_name',
                    width: 100,
                    sortable: true,
                    align: 'left'
                },
                {
                    display: '建物面積',
                    name: 'building_area',
                    width: 100,
                    sortable: true,
                    align: 'left'
                },
                {
                    display: '總價',
                    name: 'sale_total',
                    width: 100,
                    sortable: true,
                    align: 'left'
                },
                {
                    display: '車位數',
                    name: 'with_parking_number',
                    width: 100,
                    sortable: true,
                    align: 'left'
                },
                {
                    display: '建物門牌',
                    name: 'house_building',
                    width: 100,
                    sortable: true,
                    align: 'left'
                }
            ],
            buttons: [
                {
                    name: '編輯',
                    bclass: 'edit',
                    onpress: Example4
                }
                ,
                {
                    name: 'Excel',
                    bclass: 'coffee',
                    onpress: Example4
                }
                ,
                {
                    name: '配對',
                    bclass: 'pattern',
                    onpress: Example4
                }
                ,
                {
                    name: '删除',
                    bclass: 'delete',
                    onpress: Example4
                }
                ,
                {
                    separator: true
                }
            ],   
            
            sortname: '<?=$orderby;?>',
            sortorder: '<?=$sort;?>',
            usepager: true,
            title: '物件清單',
            checkbox: true, // 是否要多選框  
            useRp: true,
            rp: 10,
            width: 'auto',
            height: 'auto',
            procmsg: '資料讀取中，請稍後…',
            nomsg: '找不到符合絛件的資料',
            //margin: 10px 1px 1px -53px
        });
        function Example4(com, grid) {

            if (com == '删除') {
                var empty_str ='';
                var _fg =true;
                  $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                    var str2 = str.split('</div>');
                    var str = str2[0].split('>');                    


                    if(_fg){

                      _fg = false;
                      empty_str+= parseInt(str[1]);

                    }else{

                      empty_str+= ","+parseInt(str[1]);

                    }
                });  

                $.post('/object/save_object_id', {

                        id : empty_str ,
                        is_del : '0'

                }, function(data) {
                        
                        $.post('/object/del_object_id', {
                                          
                        }, function(data) {  
                             $(".flexme4").flexReload();    
                        });       
                });  
            }else if (com == '編輯') {


                
                  $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                    var str2 = str.split('</div>');
                    var str = str2[0].split('>');

                    var url = '/object/data_edit/'+parseInt(str[1]);
                 
                    document.location.href = url;
                    
                });  

                 

            }
            else if (com == '配對') {
                var tr_ed = $('.trSelected', grid).length;

                if(tr_ed == 1 ){

                    $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                    var str2 = str.split('</div>');
                    var str = str2[0].split('>');

                    var url = '/pair/object?id='+parseInt(str[1]);
                 
                    document.location.href = url;
                    
                    }); 
                 
                 

                }else{
                    alert('一次只能選取一個');
                }                
            }
            else if (com == 'Add') {

            }
            else if (com == 'Excel') { 
                
                var empty_str ='';
                var _fg =true;
                $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                    var str2 = str.split('</div>');
                    var str = str2[0].split('>');

                    if(_fg){
                      _fg = false;
                      empty_str+= parseInt(str[1]);
                    }else{
                      empty_str+= ","+parseInt(str[1]);

                    }
                });

                    $.post('/object/save_object_id', {
                        id : empty_str ,
                        is_del : '0'
                    }, function(data) {
                              var url = '/object/excel';                
                              document.location.href = url;          
                    });                                  
            }



        }


        function save_client(id) {

            $.get('/client/get_save_client_id', {
                id: id
            }, function(data) {

                //alert(data)

            });
        }


        $("document").ready(function() {

            setTimeout('query()', 200);

        });




        function query() {
            
            var where_sql = $("#where_sql").val();
            
            
            $(".flexme4").flexOptions(
                    {newp: 1, params:
                                [
                                    {name: 'where_sql',
                                        value: where_sql}
                                ]
                    }).flexReload();
        }

    </script>



</div>
<?=
isset($footer) ? $footer : ''?>